<?php
/**
 * @author Ricardo
 *
 */
class Markers{

	private $id;
	private $name;
	private $lat;
	private $lng;
	private $cep;
	private $city;
	private $state;
	private $sector;
	private $type;
	private $fone;
	private $address;
	private $cost;
	private $payment;
	private $number;
	private $image;
	private $fk_client;

	public function Markers(){}
	
	public function set($id, $name, $lat, $lng, $cep, $city, $state, $sector, $type, $fone, $address, $cost, $payment, $number, $image, $fk_client){
		$this->address=$address;
		$this->cep=$cep;
		$this->city=$city;
		$this->cost=$cost;
		$this->fone=$fone;
		$this->id=$id;
		$this->image=$image;
		$this->lat=$lat;
		$this->lng=$lng;
		$this->name=$name;
		$this->number=$number;
		$this->payment=$payment;
		$this->sector=$sector;
		$this->state=$state;
		$this->type=$type;
		$this->fk_client=$fk_client;
	}

	function save(){
		$sql="INSERT INTO markers
		(id,
		name,
		address,
		lat,
		lng,
		TYPE,
		fone,
		city,
		sector,
		state,
		cep,
		cost,
		payment,
		number,
		image,
		fk_client
		)
		VALUES
		('$this->id',
		'$this->name',
		'$this->address',
		'$this->lat',
		'$this->lng',
		'$this->type',
		'$this->fone',
		'$this->city',
		'$this->sector',
		'$this->state',
		'$this->cep',
		'$this->cost',
		'$this->payment',
		'$this->number',
		'$this->image',
		'$this->fk_client'
		);";
		mysql_query($sql) or die("Houver um erro ao tentar cadastrar o estacionamento !<br><br>".mysql_error());
	}
	
	public function serch($clientId){
		$arrayList = new ArrayList();
	
		$sql = "SELECT * FROM markers WHERE fk_client = ".$clientId;
		$markers = mysql_query($sql) or die("Houve um erro ao consultar um estacionamento !<br><br>".mysql_error());
		
		while($marker = mysql_fetch_array($markers)){
		
			$address=$marker['address'];
			$cep=$marker['cep'];
			$city=$marker['city'];
			$cost=$marker['cost'];
			$fone=$marker['fone'];
			$id=$marker['id'];
			$image=$marker['image'];
			$lat=$marker['lat'];
			$lng=$marker['lng'];
			$name=$marker['name'];
			$number=$marker['number'];
			$payment=$marker['payment'];
			$sector=$marker['sector'];
			$state=$marker['state'];
			$type=$marker['type'];
			$fk_client=$marker['fk_client'];
		
			$objMarker = new Markers();
			$objMarker->set($id, $name, $lat, $lng, $cep, $city, $state, $sector, $type, $fone, $address, $cost, $payment, $number, $image, $fk_client);
			
			$arrayList->add($objMarker);
		}
		
		//retorna um ArrayList com os objetos markers
		return $arrayList;
		
	}
	
	public function delete(){
		$sql = "DELETE FROM markers WHERE id = '$this->id' ;";
		mysql_query($sql) or die("Houver um erro ao tentar deletar o estacionamento");
	}
	
	public function setId($id){
		$this->id = $id;
	}
	
	public function setName($name){
		$this->name = $name;
	}

	public function getName(){
		return $this->name;
	}
	
	public function getAddress(){
		return $this->address;
	}
	
	public function getId(){
		return $this->id;
	}
	
	public function getType(){
		return $this->type;
	}
	
	public function super(){
		return $this;
	}
}
?>